/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-09-07
 * Time:23:43
 */
public class Demo19 {
    static class waitTast implements Runnable{
        private Object locker;

        public waitTast(Object locker) {
            this.locker = locker;
        }

        @Override
        public void run() {
            synchronized (locker) {
                while (true) {
                    try {
                        System.out.println("wait开始");
                        locker.wait();
                        System.out.println("wait结束");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }
    }

    static class notifyTast implements Runnable{
        private Object locker;

        public notifyTast(Object locker) {
            this.locker = locker;
        }

//        @Override
//        public void run() {
//            synchronized (locker) {
//                System.out.println("notify开始");
//                locker.notify();
//                System.out.println("notify结束");
//            }
//        }

        @Override
        public void run() {
            synchronized (locker) {
                System.out.println("notifyAll开始");
                locker.notifyAll();
                System.out.println("notifyAll结束");
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(new waitTast(locker));
        Thread t2 = new Thread(new waitTast(locker));
        Thread t3 = new Thread(new waitTast(locker));
        Thread t4 = new Thread(new notifyTast(locker));
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(1000);
        t4.start();
    }

//    public static void main(String[] args) throws InterruptedException {
//        Object locker = new Object();
//        Thread t1 = new Thread(new waitTast(locker));
//        Thread t2 = new Thread(new notifyTast(locker));
//        t1.start();
//        Thread.sleep(1000);
//        t2.start();
//    }

}
